﻿using System;

namespace UniRx.Operators
{
	// Token: 0x020002FA RID: 762
	internal class SelectWhereObservable<T, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x0600101C RID: 4124 RVA: 0x0004AA64 File Offset: 0x00048E64
		public SelectWhereObservable(IObservable<T> source, Func<T, TR> selector, Func<TR, bool> predicate) : base(source.IsRequiredSubscribeOnCurrentThread<T>())
		{
			this.source = source;
			this.selector = selector;
			this.predicate = predicate;
		}

		// Token: 0x0600101D RID: 4125 RVA: 0x0004AA87 File Offset: 0x00048E87
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return this.source.Subscribe(new SelectWhereObservable<T, TR>.SelectWhere(this, observer, cancel));
		}

		// Token: 0x04000972 RID: 2418
		private readonly IObservable<T> source;

		// Token: 0x04000973 RID: 2419
		private readonly Func<T, TR> selector;

		// Token: 0x04000974 RID: 2420
		private readonly Func<TR, bool> predicate;

		// Token: 0x020002FB RID: 763
		private class SelectWhere : OperatorObserverBase<T, TR>
		{
			// Token: 0x0600101E RID: 4126 RVA: 0x0004AA9C File Offset: 0x00048E9C
			public SelectWhere(SelectWhereObservable<T, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x0600101F RID: 4127 RVA: 0x0004AAB0 File Offset: 0x00048EB0
			public override void OnNext(T value)
			{
				TR tr = default(TR);
				try
				{
					tr = this.parent.selector(value);
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				bool flag = false;
				try
				{
					flag = this.parent.predicate(tr);
				}
				catch (Exception error2)
				{
					try
					{
						this.observer.OnError(error2);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				if (flag)
				{
					this.observer.OnNext(tr);
				}
			}

			// Token: 0x06001020 RID: 4128 RVA: 0x0004AB84 File Offset: 0x00048F84
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06001021 RID: 4129 RVA: 0x0004ABBC File Offset: 0x00048FBC
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000975 RID: 2421
			private readonly SelectWhereObservable<T, TR> parent;
		}
	}
}
